#pragma once
#include "SimpleDef.h"

#define VIDEO_TEXT_MODE_FOREGROUND_BLACK ((0) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_BLUE ((1) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_GREEN ((2) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_CYAN ((3) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_RED ((4) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_MAGENTA ((5) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_BROWN ((6) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_WHITE ((7) << 8)
#define VIDEO_TEXT_MODE_FOREGROUND_BRIGHT ((8) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_BLACK ((0 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_BLUE ((1 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_GREEN ((2 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_CYAN ((3 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_RED ((4 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_MAGENTA ((5 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_BROWN ((6 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_WHITE ((7 << 4) << 8)
#define VIDEO_TEXT_MODE_BACKGROUND_FLASH ((1 << 7) << 8)

#define VIDEO_TEXT_MODE_COLOR_INFO (VIDEO_TEXT_MODE_FOREGROUND_WHITE | VIDEO_TEXT_MODE_BACKGROUND_BLACK | VIDEO_TEXT_MODE_FOREGROUND_BRIGHT)
#define VIDEO_TEXT_MODE_COLOR_OK (VIDEO_TEXT_MODE_FOREGROUND_GREEN | VIDEO_TEXT_MODE_BACKGROUND_BLACK | VIDEO_TEXT_MODE_FOREGROUND_BRIGHT)
#define VIDEO_TEXT_MODE_COLOR_WARN (VIDEO_TEXT_MODE_FOREGROUND_BROWN | VIDEO_TEXT_MODE_BACKGROUND_BLACK | VIDEO_TEXT_MODE_FOREGROUND_BRIGHT)
#define VIDEO_TEXT_MODE_COLOR_ERR (VIDEO_TEXT_MODE_FOREGROUND_RED | VIDEO_TEXT_MODE_BACKGROUND_BLACK | VIDEO_TEXT_MODE_FOREGROUND_BRIGHT)

#define CRT_CONTROLLER_ADDR_REG (0x03D4) /* CRT 地址端口 */
#define CRT_CONTROLLER_DATA_REG (0x03D5) /* CRT 数据端口 */
#define CRT_CONTROLLER_START_ADDR_HIGH (0x0C) /* 显示起始地址高 8 位 */
#define CRT_CONTROLLER_START_ADDR_LOW (0x0D) /* 显示起始地址低 8 位 */
#define CRT_CONTROLLER_CURSOR_LOCATION_HIGH (0x0E) /* 选项：光标地址高字节 */
#define CRT_CONTROLLER_CURSOR_LOCATION_LOW (0x0F)

extern int g_VideoTextModeColor;

WORD VideoTextModeLocateCursor(void);
WORD VideoTextModeLocateStart(void);
void VideoTextModePositionCursor(WORD wPosition);
void VideoTextModePositionStart(WORD wPosition);
void  VideoTextModeCopyLine(DWORD dwDstLine, DWORD dwSrcLine);
void VideoTextModeClearLine(DWORD dwStart, DWORD dwcLines);
int VideoTextModePutChar(int nChar);
void VideoTextModeClearScreen(void);
int VideoTextModePutString(LPCSTR pcstr);
void VideoTextModeSetColor(int nColor);
int VideoTextModeGetColor(void);
int VideoTextModePrintFormatted(LPCSTR lpFmt, ...);
#define printk(...) VideoTextModePrintFormatted(__VA_ARGS__)

#define kerror(...) { \
    int tmp = g_VideoTextModeColor; \
    g_VideoTextModeColor = VIDEO_TEXT_MODE_COLOR_ERR; \
    printk(__VA_ARGS__); \
    g_VideoTextModeColor = tmp; \
}

#define kwarn(...) { \
    int tmp = g_VideoTextModeColor; \
    g_VideoTextModeColor = VIDEO_TEXT_MODE_COLOR_WARN; \
    printk(__VA_ARGS__); \
    g_VideoTextModeColor = tmp; \
}

#define kmessage(...) { \
    int tmp = g_VideoTextModeColor; \
    g_VideoTextModeColor = VIDEO_TEXT_MODE_COLOR_INFO; \
    printk(__VA_ARGS__); \
    g_VideoTextModeColor = tmp; \
}

#define ksuccess(...) { \
    int tmp = g_VideoTextModeColor; \
    g_VideoTextModeColor = VIDEO_TEXT_MODE_COLOR_OK; \
    printk(__VA_ARGS__); \
    g_VideoTextModeColor = tmp; \
}
